<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			let students =[]
			function init(){
				let xhr =new XMLHttpRequest();
				xhr.open("GET","stus.xml",false);
				xhr.send();
				var data = xhr.responseXML;
				students = data.querySelectorAll("student");
				document.getElementById("sno").value=students[0].getAttribute("sno")
				document.getElementById("sname").value=students[0].getAttribute("sname")
			}
		</script>
	</head>
	<body onload="init()">
		学号：<input type="text" id="sno"><br>
		姓名：<input type="text" id="sname"><br>
		<button type="button">下一个</button>
		<script type="text/javascript">
			let index=1;
			document.querySelector("button").onclick=function(){
				index++
				if(index>students.length){
					index=0
				}
				document.getElementById("sno").value=students[index].getAttribute("sno")
				document.getElementById("sname").value=students[index].getAttribute("sname")
			}
		</script>
	</body>
</html>
